<?php

Raise::load('core.RaiseObject');

/**
 * RaiseDbTableColumn class
 * Represents a table column information from the database
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.db.core
 * @since 1.2
 */
class RaiseDbTableColumn extends RaiseObject {

    /**
     * The name of the column
     * @var string
     */
    private $name;

    /**
     * Is the column the primary key or part of the composite primary key
     * @var boolean
     */
    private $primaryKey;

    /**
     * Does the column auto increment
     * @var boolean
     */
    private $autoIncrement;

    /**
     * Can NULL be set to the column
     * @var boolean
     */
    private $null;

    /**
     * The datatype of the column
     * Use one of the constants in RaiseVariable
     * @var string
     */
    private $type;

      /**
     * Get or set the name of this column
     * @param string $n (optional) Set a new name for this column
     * @return string
     */
    public function name($n = null){
        if(func_num_args() == 1){
            $this->name = $n;
        }
        return $this->name;
    }

    /**
     * Get or set whether this table column is a primary key or not
     * @param boolean $p (optional) Set whether the column is a primary key or not
     * @return boolean
     */
    public function primaryKey($p = null){
        if(func_num_args() == 1){
            $this->primaryKey = $p;
        }
        return $this->primaryKey;
    }

    /**
     * Get or set whether the column is autoincremental or not
     * @param boolean $a (optional) Set whether the column is auto incremented.
     * @return boolean
     */
    public function autoIncrement($a = null){
        if(func_num_args() == 1){
            $this->autoIncrement = $a;
        }
        return $this->autoIncrement;
    }

    /**
     * Get or set whether the column can be set to NULL or not
     * @param boolean $n (optional) Set whether the column can be set to NULL or not
     * @return boolean
     */
    public function null($n = null){
        if(func_num_args() == 1){
            $this->null = $n;
        }
        return $this->null;
    }

    /**
     * Get or set the data type of this column
     * @param string $t (optional) Set the data type of this column
     * @return string
     */
    public function type($t = null){
        if(func_num_args() == 1){
            $this->type = $t;
        }
        return $this->type;
    }

    public function __toString() {
        return $this->name();
    }

}